<div class="layuimini-container">
        <div class="layuimini-main">
         <h3>后台配置</h3>
         <hr>
            <div class="layui-form" lay-filter="admin-config">
            <div class="layui-tab">
                <ul class="layui-tab-title">
                    <li class="layui-this">信息显示</li>
                    <li>各种开关</li>
                    <li>输入框</li>
                </ul>
                <div class="layui-tab-content pt20" style="width: 1050px">
                    <div class="layui-tab-item layui-show my-textarea"></div>
                    <div class="layui-tab-item my-switch"></div>
                    <div class="layui-tab-item my-input"></div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="common-submit-save" data-save-url="/admin/set/update.htm">确认提交</button>
                </div>
                </div>
            </div>
            </div>
        </div>

        </div>
    </div>

<script>
    const render_dom = function(data) {
            let dom1 = '', dom2 = '', dom3 = '';
            data.map(function(v){
                if( v.data_type === 'input' || v.data_type === 'input-sm' ){
                    let style = '';
                    if( v.data_type === 'input-sm'){
                        style='style="width:100px"'
                    }
                    dom2 += '<div class="layui-form-item"><label class="layui-form-label">' + v.cn_name + '</label>'
                        + '<div class="layui-input-block">'+
                        '<input type="text" name="'+v.name+'" value="'+ v.value +'" class="layui-input" '+ style + '>'
                        + '<div class="layui-form-mid layui-word-aux">' + v.desc + '</div></div></div>';
            }
            else if( v.data_type == 'switch')
            {
                dom3 += '<div class="layui-form-item"><label class="layui-form-label">' + v.cn_name + '</label>'
                    + '<div class="layui-input-block">'+
                    '<input lay-filter="set_switch" type="checkbox" name="'+v.name+'" lay-skin="switch" '+ (v.value === 'y' ? 'checked' : '') + ' lay-text="开启|关闭"><br>'
                        + '<div class="layui-form-mid layui-word-aux">' + v.desc + '</div></div></div>';
            }
            else if( v.data_type == 'textarea' )
            {
                dom1 += '<div class="layui-form-item"><label class="layui-form-label">' + v.cn_name + '</label>'
                    + '<div class="layui-input-block">'+
                    '<textarea class="layui-textarea" name="'+v.name+'" placeholder="'+v.desc+'">' +v.value+'</textarea>' +
                    '<div class="layui-form-mid layui-word-aux">' + v.desc + '</div></div></div>';
            }
        })
        return [dom1,dom2,dom3];
    };
    http.get('/admin/set.htm').done(function(res){
        let dom;
            if(res.code == 200)
        {
                const $button_dom = '<div class="layui-form-item"><div class="layui-input-block">'
                        + '<button class="layui-btn" lay-submit lay-filter="common-submit-save" data-save-url="/admin/set/update.htm">确认提交</button></div></div>';
             if( res.result && res.result.length > 1 ){
                dom = render_dom(res.result);
                $('.my-textarea').html(dom[0]);
                $('.my-input').html(dom[1]);
                $('.my-switch').html(dom[2])
            }
            form.render(null,'admin-config')
        }
    })
    form.on('switch(set_switch)', function(data){
            const field = data.elem.name,
                    value = data.elem.checked === true ? 'y' : 'n';
            if(field === 'is_check_baidu_uri' && value === 'y'){
                let cookie = $('textarea[name="check_baidu_uri_cookie"]').val();
                if(!cookie){
                    layer.alert('请先填写Cookie!');
                    return ;
                }
            }
            http.post('/admin/set/set_switch.htm',{data : {name:field,value:value}})
            .done(function(res){
                    layer.msg(res.msg)
            })
    })
</script>